package com.insigma.business.qrcode.placement.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alipay.api.domain.Businessarea;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.insigma.business.common.utils.CurrentUserUtil;
import com.insigma.business.common.utils.MinIoUtil;
import com.insigma.business.common.utils.ToolsHelper;
import com.insigma.business.qrcode.common.dao.SoldierBasicInfoBDao;
import com.insigma.business.qrcode.common.dto.ErrorCodeEnum;
import com.insigma.business.qrcode.common.dto.search.SoldierBasicInfoBSearch;
import com.insigma.business.qrcode.common.entity.SoldierBasicInfoB;
import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.template.BasePagingResponse;
import com.insigma.business.qrcode.common.template.area.BaseProviderImpl;
import com.insigma.business.qrcode.common.template.area.ScenarioCodeEnum;
import com.insigma.business.qrcode.common.template.area.ServiceCallback;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.common.util.BizException;
import com.insigma.business.qrcode.common.util.CommonConstant;
import com.insigma.business.qrcode.common.util.ResponseUtils;
import com.insigma.business.qrcode.common.vo.BaseResponse;
import com.insigma.business.qrcode.placement.dao.*;
import com.insigma.business.qrcode.placement.dto.*;
import com.insigma.business.qrcode.placement.dto.excel.*;
import com.insigma.business.qrcode.placement.dto.request.*;
import com.insigma.business.qrcode.placement.entity.*;
import com.insigma.business.qrcode.placement.service.CodeOnPlacementService;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.framework.encryption.util.SM4Utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author max
 * @Description:
 * @date 2024-04-16 14:12
 */
@Slf4j
@Service("codeOnPlacementPubService")
public class CodeOnPlacementServiceImpl extends BaseProviderImpl implements CodeOnPlacementService {

    @Resource
    private SequenceGenerator sequenceGenerator;

    @Resource
    private PlacementPubInfoDAO placementPubInfoDAO;

    @Resource
    private ResetSubsidyDistrDAO resetSubsidyDistrDAO;

    @Resource
    private ResetSubsidyDistrDetlDAO resetSubsidyDistrDetlDAO;

    @Resource
    private FlexSelfSubsidyDistrDetlDAO flexSelfSubsidyDistrDetlDAO;

    @Resource
    private SoldierBasicInfoBDao soldierBasicInfoBDao;

    @Resource
    private PsnBankInfoBDAO psnBankInfoBDAO;

    @Override
    public BaseResponse<String> addPlacementPubInfo(PlacementPubInfoAddUpdRequestDTO requestDTO) {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "新增公示信息的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getPubTitle(),"公示标题不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getAdmdvs(),"接收地区不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getPubType(),"公示类型不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getPubText(),"公示正文不能为空");
                BizCheckUtil.checkNotNull(requestDTO.getBeginTime(),"公示开始时间不能为空");
                BizCheckUtil.checkNotNull(requestDTO.getEndTime(),"公示结束时间不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getPublishFlag(), "发布状态不能为空");
                if(!CommonConstant.PUBLISH_FLAG_NO.equals(requestDTO.getPublishFlag()) && !CommonConstant.PUBLISH_FLAG_YES.equals(requestDTO.getPublishFlag())){
                    throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "发布状态不在配置的范围内");
                }
            }

            @Override
            public void executeService() {
                PlacementPubInfoEntity addEntity = new PlacementPubInfoEntity();
                BeanUtils.copyProperties(requestDTO, addEntity);
                addEntity.setPlacementPubInfoId(sequenceGenerator.genKey(SequenceNameConstant.PLACEMENT_PUB_INFO_ID));
                addEntity.setPublishEmpName("");
                addEntity.setIsDeleted(CommonConstant.IS_DELETED_NO);
                addEntity.setCreatorId(CurrentUserUtil.getCurrentUser().getUserId());
                addEntity.setCreatorName(CurrentUserUtil.getCurrentUser().getDisplayName());
                addEntity.setCreateDatetime(new Date());
                addEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                addEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                addEntity.setModifyDatetime(new Date());
                placementPubInfoDAO.insert(addEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, addEntity.getPlacementPubInfoId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_PUB_ADD;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> updatePlacementPubInfo(PlacementPubInfoAddUpdRequestDTO requestDTO) {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "修改公示信息的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getPlacementPubInfoId(),"公示ID不能为空");
                if(!CommonConstant.PUBLISH_FLAG_NO.equals(requestDTO.getPublishFlag()) && !CommonConstant.PUBLISH_FLAG_YES.equals(requestDTO.getPublishFlag())){
                    throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "发布状态不在配置的范围内");
                }
            }

            @Override
            public void executeService() {
                PlacementPubInfoEntity updateEntity = new PlacementPubInfoEntity();
                BeanUtils.copyProperties(requestDTO, updateEntity);
                updateEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                updateEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                updateEntity.setModifyDatetime(new Date());
                placementPubInfoDAO.updateById(updateEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, updateEntity.getPlacementPubInfoId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_PUB_UPDATE;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> delPlacementPubInfo(PlacementPubInfoAddUpdRequestDTO requestDTO) {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "删除公示信息的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getPlacementPubInfoId(),"公示ID不能为空");
            }

            @Override
            public void executeService() {
                PlacementPubInfoEntity delEntity = new PlacementPubInfoEntity();
                delEntity.setPlacementPubInfoId(requestDTO.getPlacementPubInfoId());
                delEntity.setIsDeleted(CommonConstant.IS_DELETED_YES);
                delEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                delEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                delEntity.setModifyDatetime(new Date());
                placementPubInfoDAO.updateById(delEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, delEntity.getPlacementPubInfoId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_PUB_DEL;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<List<PlacementPubInfoDTO>> queryPlacementPubInfoList(PlacementPubInfoQueryRequestDTO requestDTO) {
        final BasePagingResponse<List<PlacementPubInfoDTO>> basePagingResponse = new BasePagingResponse<>();
        serviceTemplate.execute(basePagingResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "查询公示信息的入参不能为空");
                BizCheckUtil.checkNotNull(requestDTO.getPageNo(), "起始页不能为空");
                BizCheckUtil.checkNotNull(requestDTO.getPageSize(), "每页大小不能为空");
            }

            @Override
            public void executeService() {
                PlacementPubInfoEntity queryEntity = new PlacementPubInfoEntity();
                BeanUtils.copyProperties(requestDTO, queryEntity);
                PageHelper.startPage(requestDTO.getPageNo(), requestDTO.getPageSize());
                //页面传入的开始结束日期改为查询发布修改时间
                List<PlacementPubInfoEntity> placementPubInfoEntities = placementPubInfoDAO.queryByCondition(queryEntity);
                PageInfo<PlacementPubInfoEntity> pageInfo = new PageInfo<>(placementPubInfoEntities);
                List<PlacementPubInfoDTO> placementPubInfoDTOList = ToolsHelper.copyListProperties(pageInfo.getList(), PlacementPubInfoDTO::new);
                ResponseUtils.buildSuccessPagingResponse(basePagingResponse, placementPubInfoDTOList, requestDTO,pageInfo.getTotal());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_PUB_QUERY_LIST;
            }
        });
        return basePagingResponse;
    }

    @Override
    public BaseResponse<PlacementPubInfoDTO> queryPlacementPubInfo(PlacementPubInfoQueryRequestDTO requestDTO) {
        final BaseResponse<PlacementPubInfoDTO> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "查询公示详情的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getPlacementPubInfoId(),"公示ID不能为空");
            }

            @Override
            public void executeService() {
                PlacementPubInfoEntity queryEntity = new PlacementPubInfoEntity();
                BeanUtils.copyProperties(requestDTO, queryEntity);
                List<PlacementPubInfoEntity> placementPubInfoEntities = placementPubInfoDAO.queryByCondition(queryEntity);
                if(CollectionUtils.isNotEmpty(placementPubInfoEntities)){
                    PlacementPubInfoDTO placementPubInfoDTO = new PlacementPubInfoDTO();
                    BeanUtils.copyProperties(placementPubInfoEntities.get(0), placementPubInfoDTO);
                    ResponseUtils.setupSuccessResponse(baseResponse, placementPubInfoDTO);
                }else {
                    ResponseUtils.buildSuccessResponse(new PlacementPubInfoDTO());
                }
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_PUB_QUERY_DETL;
            }
        });
        return baseResponse;
    }

    @Override
    public void downloadResetTemplate(HttpServletResponse response) throws Exception {
        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("模板文件.xlsx", "UTF-8"));
        EasyExcel.write(response.getOutputStream(), ResetSubsidyDistrInOutDTO.class).sheet("sheet1").doWrite(new ArrayList<>());
    }

    @Override
    public BaseResponse<ImportResDTO> importResetSubsidyDistr(MultipartFile file) throws Exception {
        if(ToolsHelper.isEmpty(file)){
            throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "导入文件为空");
        }
        ResetSubsidyDistrListener listener = new ResetSubsidyDistrListener();
        EasyExcel.read(file.getInputStream(), ResetSubsidyDistrInOutDTO.class, listener).sheet().doRead();
        List<ResetSubsidyDistrInOutDTO> passList = listener.getValidatePassList();
        List<ResetSubsidyDistrInOutDTO> notPassList = listener.getValidateNotPassList();
        if(CollectionUtils.isEmpty(passList) && CollectionUtils.isEmpty(notPassList)){
            throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "导入的列表为空");
        }
        //对校验通过的数据处理
        List<ResetSubsidyDistrDetlEntity> addDetlEntities = new ArrayList<>();
        for (ResetSubsidyDistrInOutDTO importDTO : passList){
            String encipherIdCardNum = SM4Utils.encryptDataByECB(importDTO.getIdCardNum(), "Epsoft@2024!@#$%");
            importDTO.setIdCardNum(encipherIdCardNum);
            //查询soldierId
            SoldierBasicInfoBSearch searchEntity = new SoldierBasicInfoBSearch();
            searchEntity.setIdcard(importDTO.getIdCardNum());
            List<SoldierBasicInfoB> searchEntityResList = soldierBasicInfoBDao.search(searchEntity);
            if(CollectionUtils.isEmpty(searchEntityResList)){
                importDTO.setMemo(importDTO.getMemo() + "||没有查询到该人员基础信息;");
                notPassList.add(importDTO);
                continue;
            }
            String soldierId = searchEntityResList.get(0).getSoldierId();

            //每人每年每月一条明细
            ResetSubsidyDistrDetlEntity queryDetlEntity = new ResetSubsidyDistrDetlEntity();
            queryDetlEntity.setIdCardNum(importDTO.getIdCardNum());
            queryDetlEntity.setPayYear(importDTO.getPayYear());
            queryDetlEntity.setPayMonth(importDTO.getPayMonth());
            List<ResetSubsidyDistrDetlEntity> resetSubsidyDistrDetlEntityList = resetSubsidyDistrDetlDAO.queryByCondition(queryDetlEntity);
            if(CollectionUtils.isNotEmpty(resetSubsidyDistrDetlEntityList)){
                importDTO.setMemo(importDTO.getMemo() + "||该人员当前年月已存在待安置补助数据;");
                notPassList.add(importDTO);
                continue;
            }
            //不能有灵活就业/自主就业一次性补助
            FlexSelfSubsidyDistrDetlEntity queryEntity = new FlexSelfSubsidyDistrDetlEntity();
            queryEntity.setIdCardNum(importDTO.getIdCardNum());
            List<FlexSelfSubsidyDistrDetlEntity> flexSelfSubsidyDistrDetlEntities = flexSelfSubsidyDistrDetlDAO.queryByCondition(queryEntity);
            if(CollectionUtils.isNotEmpty(flexSelfSubsidyDistrDetlEntities)){
                importDTO.setMemo((ToolsHelper.isEmpty(importDTO.getMemo()) ? "" : importDTO.getMemo()) + "||该人员已存在灵活就业或自主就业一次性补助数据;");
                notPassList.add(importDTO);
                continue;
            }

            //封装主表数据
            String resetSubsidyDistrId;
            ResetSubsidyDistrEntity queryMainEntity = new ResetSubsidyDistrEntity();
            queryMainEntity.setIdCardNum(importDTO.getIdCardNum());
            List<ResetSubsidyDistrEntity> resetSubsidyDistrEntities = resetSubsidyDistrDAO.queryByCondition(queryMainEntity);
            if(CollectionUtils.isEmpty(resetSubsidyDistrEntities)){
                //查询不到时新增主表数据
                ResetSubsidyDistrEntity addMainEntity = new ResetSubsidyDistrEntity();
                BeanUtils.copyProperties(importDTO, addMainEntity);
                addMainEntity.setResetSubsidyDistrId(sequenceGenerator.genKey(SequenceNameConstant.RESET_SUBSIDY_DISTR_ID));
                addMainEntity.setSoldierId(soldierId);
                addMainEntity.setCreatorId(CurrentUserUtil.getCurrentUser().getUserId());
                addMainEntity.setCreatorName(CurrentUserUtil.getCurrentUser().getDisplayName());
                addMainEntity.setCreateDatetime(new Date());
                addMainEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                addMainEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                addMainEntity.setModifyDatetime(new Date());
                resetSubsidyDistrDAO.insert(addMainEntity);
                resetSubsidyDistrId = addMainEntity.getResetSubsidyDistrId();
            }else {
                resetSubsidyDistrId = resetSubsidyDistrEntities.get(0).getResetSubsidyDistrId();
            }

            //封装明细数据
            ResetSubsidyDistrDetlEntity addDetlEntity = new ResetSubsidyDistrDetlEntity();
            BeanUtils.copyProperties(importDTO, addDetlEntity);
            addDetlEntity.setResetSubsidyDistrDetlId(sequenceGenerator.genKey(SequenceNameConstant.RESET_SUBSIDY_DISTR_DETL_ID));
            addDetlEntity.setSoldierId(soldierId);
            addDetlEntity.setResetSubsidyDistrId(resetSubsidyDistrId);
            addDetlEntity.setSubsidyType(CommonConstant.SUBSIDY_TYPE_RESET);
            addDetlEntity.setConfirmFlag(CommonConstant.CONFIRM_FLAG_NO);
            addDetlEntity.setIsDeleted(CommonConstant.IS_DELETED_NO);
            addDetlEntity.setCreatorId(CurrentUserUtil.getCurrentUser().getUserId());
            addDetlEntity.setCreatorName(CurrentUserUtil.getCurrentUser().getDisplayName());
            addDetlEntity.setCreateDatetime(new Date());
            addDetlEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
            addDetlEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
            addDetlEntity.setModifyDatetime(new Date());
            addDetlEntities.add(addDetlEntity);
        }

        if(CollectionUtils.isNotEmpty(addDetlEntities)){
            resetSubsidyDistrDetlDAO.insertBatch(addDetlEntities);
        }

        //封装返回数据
        ImportResDTO resDTO = new ImportResDTO();
        resDTO.setSuccessNum(addDetlEntities.size());
        resDTO.setFailNum(notPassList.size());
        if(CollectionUtils.isNotEmpty(notPassList)){
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                EasyExcel.write(out, FlexSelfSubsidyDistrInOutDTO.class).sheet("sheet1").doWrite(notPassList);
                //失败数据excel上传并返回地址
                resDTO.setFilePath(MinIoUtil.upload(out.toByteArray(), "error_data.xlsx", "qrcode", "code_on_placement"));
            }catch (Exception e){
                log.error("待安置补助导入后,失败文件地址获取失败,原因:{}", e.getMessage());
                e.printStackTrace();
            }
        }
        BaseResponse<ImportResDTO> baseResponse = new BaseResponse<>();
        ResponseUtils.setupSuccessResponse(baseResponse, resDTO);
        return  baseResponse;
    }

    @Override
    public BaseResponse<List<ResetSubsidyDistrDetlDTO>> queryResetSubsidyDistrDetlList(ResetSubsidyDistrDetlQueryRequestDTO requestDTO) throws Exception {
        final BasePagingResponse<List<ResetSubsidyDistrDetlDTO>> basePagingResponse = new BasePagingResponse<>();
        serviceTemplate.execute(basePagingResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "查询待安置生活补助明细的入参不能为空");
                BizCheckUtil.checkNotNull(requestDTO.getPageNo(), "起始页不能为空");
                BizCheckUtil.checkNotNull(requestDTO.getPageSize(), "每页大小不能为空");
            }

            @Override
            public void executeService() {
                ResetSubsidyDistrDetlEntity queryEntity = new ResetSubsidyDistrDetlEntity();
                BeanUtils.copyProperties(requestDTO, queryEntity);
                PageHelper.startPage(requestDTO.getPageNo(), requestDTO.getPageSize());
                List<ResetSubsidyDistrDetlEntity> resetSubsidyDistrDetlEntities = resetSubsidyDistrDetlDAO.queryByCondition(queryEntity);
                PageInfo<ResetSubsidyDistrDetlEntity> pageInfo = new PageInfo<>(resetSubsidyDistrDetlEntities);
                List<ResetSubsidyDistrDetlDTO> resetSubsidyDistrDetlDTOList = ToolsHelper.copyListProperties(pageInfo.getList(), ResetSubsidyDistrDetlDTO::new);
                resetSubsidyDistrDetlDTOList.stream().forEach(o -> {
                    o.setIdCardNum(SM4Utils.decryptDataECB(o.getIdCardNum(), "Epsoft@2024!@#$%"));
                });
                ResponseUtils.buildSuccessPagingResponse(basePagingResponse, resetSubsidyDistrDetlDTOList, requestDTO,pageInfo.getTotal());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_RESET_QUERY_LIST;
            }
        });
        return basePagingResponse;
    }

    @Override
    public BaseResponse<ResetSubsidyDistrDetlDTO> queryResetSubsidyDistrDetl(ResetSubsidyDistrDetlQueryRequestDTO requestDTO) throws Exception {
        final BaseResponse<ResetSubsidyDistrDetlDTO> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "查询待安置生活补助明细的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getResetSubsidyDistrDetlId(),"待安置生活补助明细ID不能为空");
            }

            @Override
            public void executeService() {
                ResetSubsidyDistrDetlEntity queryEntity = new ResetSubsidyDistrDetlEntity();
                BeanUtils.copyProperties(requestDTO, queryEntity);
                List<ResetSubsidyDistrDetlEntity> resetSubsidyDistrDetlEntities = resetSubsidyDistrDetlDAO.queryByCondition(queryEntity);
                if(CollectionUtils.isNotEmpty(resetSubsidyDistrDetlEntities)){
                    ResetSubsidyDistrDetlDTO resetSubsidyDistrDetlDTO = new ResetSubsidyDistrDetlDTO();
                    BeanUtils.copyProperties(resetSubsidyDistrDetlEntities.get(0), resetSubsidyDistrDetlDTO);
                    resetSubsidyDistrDetlDTO.setIdCardNum(SM4Utils.decryptDataECB(resetSubsidyDistrDetlDTO.getIdCardNum(), "Epsoft@2024!@#$%"));
                    ResponseUtils.setupSuccessResponse(baseResponse, resetSubsidyDistrDetlDTO);
                }else {
                    ResponseUtils.buildSuccessResponse(new ResetSubsidyDistrDetlDTO());
                }
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_RESET_QUERY_DETL;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> updateResetSubsidyDistrDetl(ResetSubsidyDistrDetlUpdRequestDTO requestDTO) throws Exception {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "修改待安置生活补助明细的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getIdCardNum(),"证件号码不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getResetSubsidyDistrDetlId(),"待安置生活补助明细ID不能为空");
            }

            @Override
            public void executeService() {
                ResetSubsidyDistrDetlEntity queryDetlEntity = new ResetSubsidyDistrDetlEntity();
                queryDetlEntity.setResetSubsidyDistrDetlId(requestDTO.getResetSubsidyDistrDetlId());
                List<ResetSubsidyDistrDetlEntity> resetSubsidyDistrDetlEntities = resetSubsidyDistrDetlDAO.queryByCondition(queryDetlEntity);
                if(CollectionUtils.isEmpty(resetSubsidyDistrDetlEntities)){
                    throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "当前待安置补助明细ID未查询到数据");
                }
                //每人每年每月一条明细,如果年月做了修改,校验与库中数据是否重复
                ResetSubsidyDistrDetlEntity entity = resetSubsidyDistrDetlEntities.get(0);
                if(!entity.getPayYear().equals(requestDTO.getPayYear()) || !entity.getPayMonth().equals(requestDTO.getPayMonth())){
                    queryDetlEntity.setIdCardNum(SM4Utils.encryptDataByECB(requestDTO.getIdCardNum(), "Epsoft@2024!@#$%"));
                    queryDetlEntity.setPayYear(requestDTO.getPayYear());
                    queryDetlEntity.setPayMonth(requestDTO.getPayMonth());
                    List<ResetSubsidyDistrDetlEntity> resetSubsidyDistrDetlEntityList = resetSubsidyDistrDetlDAO.queryByCondition(queryDetlEntity);
                    if(CollectionUtils.isNotEmpty(resetSubsidyDistrDetlEntityList)){
                        throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "该人员预期修改年月已存在对应数据,不能修改");
                    }
                }
                //操作修改
                ResetSubsidyDistrDetlEntity updateEntity = new ResetSubsidyDistrDetlEntity();
                BeanUtils.copyProperties(requestDTO, updateEntity);
                updateEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                updateEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                updateEntity.setModifyDatetime(new Date());
                resetSubsidyDistrDetlDAO.updateById(updateEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, updateEntity.getResetSubsidyDistrDetlId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_RESET_UPDATE;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> delResetSubsidyDistrDetl(ResetSubsidyDistrDetlUpdRequestDTO requestDTO) throws Exception {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "删除待安置生活补助明细的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getResetSubsidyDistrDetlId(),"待安置生活补助明细ID不能为空");
            }

            @Override
            public void executeService() {
                ResetSubsidyDistrDetlEntity delEntity = new ResetSubsidyDistrDetlEntity();
                delEntity.setResetSubsidyDistrDetlId(requestDTO.getResetSubsidyDistrDetlId());
                delEntity.setIsDeleted(CommonConstant.IS_DELETED_YES);
                delEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                delEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                delEntity.setModifyDatetime(new Date());
                resetSubsidyDistrDetlDAO.updateById(delEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, delEntity.getResetSubsidyDistrDetlId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_RESET_DEL;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> confirmResetSubsidyDistrDetl(ResetSubsidyDistrDetlUpdRequestDTO requestDTO) throws Exception {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "确认待安置生活补助的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getResetSubsidyDistrDetlId(),"待安置生活补助明细ID不能为空");
            }

            @Override
            public void executeService() {
                ResetSubsidyDistrDetlEntity delEntity = new ResetSubsidyDistrDetlEntity();
                delEntity.setResetSubsidyDistrDetlId(requestDTO.getResetSubsidyDistrDetlId());
                delEntity.setConfirmFlag(CommonConstant.CONFIRM_FLAG_YES);
                delEntity.setConfirmDatetime(new Date());
                delEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                delEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                delEntity.setModifyDatetime(new Date());
                resetSubsidyDistrDetlDAO.updateById(delEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, delEntity.getResetSubsidyDistrDetlId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_RESET_UPDATE;
            }
        });
        return baseResponse;
    }

    @Override
    public void downloadFlexSelfTemplate(HttpServletResponse response) throws Exception {
        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("模板文件.xlsx", "UTF-8"));
        EasyExcel.write(response.getOutputStream(), FlexSelfSubsidyDistrInOutDTO.class).sheet("sheet1").doWrite(new ArrayList<>());
    }

    @Override
    public BaseResponse<ImportResDTO> importFlexSelfSubsidyDistr(MultipartFile file, String subsidyType) throws Exception {
        if(ToolsHelper.isEmpty(file)){
            throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "导入文件为空");
        }
        if(ToolsHelper.isEmpty(subsidyType)){
            throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "补助类型为空");
        }
        if(!CommonConstant.SUBSIDY_TYPE_FLEX.equals(subsidyType) && !CommonConstant.SUBSIDY_TYPE_SELF.equals(subsidyType)){
            throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "需传入正确的灵活就业或自主就业补助类型");
        }
        FlexSelfSubsidyDistrListener listener = new FlexSelfSubsidyDistrListener();
        EasyExcel.read(file.getInputStream(), FlexSelfSubsidyDistrInOutDTO.class, listener).sheet().doRead();
        List<FlexSelfSubsidyDistrInOutDTO> passList = listener.getValidatePassList();
        List<FlexSelfSubsidyDistrInOutDTO> notPassList = listener.getValidateNotPassList();
        if(CollectionUtils.isEmpty(passList) && CollectionUtils.isEmpty(notPassList)){
            throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "导入的列表为空");
        }
        //对校验通过的数据处理
        List<FlexSelfSubsidyDistrDetlEntity> addDetlEntities = new ArrayList<>();
        for (FlexSelfSubsidyDistrInOutDTO importDTO : passList){
            String encipherIdCardNum = SM4Utils.encryptDataByECB(importDTO.getIdCardNum(), "Epsoft@2024!@#$%");
            importDTO.setIdCardNum(encipherIdCardNum);
            //查询soldierId
            SoldierBasicInfoBSearch searchEntity = new SoldierBasicInfoBSearch();
            searchEntity.setIdcard(importDTO.getIdCardNum());
            List<SoldierBasicInfoB> searchEntityResList = soldierBasicInfoBDao.search(searchEntity);
            if(CollectionUtils.isEmpty(searchEntityResList)){
                importDTO.setMemo(importDTO.getMemo() + "||没有查询到该人员基础信息;");
                notPassList.add(importDTO);
                continue;
            }
            String soldierId = searchEntityResList.get(0).getSoldierId();

            //每人一条明细
            FlexSelfSubsidyDistrDetlEntity queryDetlEntity = new FlexSelfSubsidyDistrDetlEntity();
            queryDetlEntity.setIdCardNum(importDTO.getIdCardNum());
            List<FlexSelfSubsidyDistrDetlEntity> flexSelfSubsidyDistrDetlEntities = flexSelfSubsidyDistrDetlDAO.queryByCondition(queryDetlEntity);
            if(CollectionUtils.isNotEmpty(flexSelfSubsidyDistrDetlEntities)){
                importDTO.setMemo((ToolsHelper.isEmpty(importDTO.getMemo()) ? "" : importDTO.getMemo()) + "||该人员当前已存在灵活就业或自主就业一次性补助数据;");
                notPassList.add(importDTO);
                continue;
            }

            //封装明细数据
            FlexSelfSubsidyDistrDetlEntity addDetlEntity = new FlexSelfSubsidyDistrDetlEntity();
            BeanUtils.copyProperties(importDTO, addDetlEntity);
            addDetlEntity.setFlexSelfSubsidyDistrDetlId(sequenceGenerator.genKey(SequenceNameConstant.FLEX_SELF_SUBSIDY_DISTR_DETL_ID));
            addDetlEntity.setSoldierId(soldierId);
            addDetlEntity.setSubsidyType(subsidyType);
            addDetlEntity.setConfirmFlag(CommonConstant.CONFIRM_FLAG_NO);
            addDetlEntity.setIsDeleted(CommonConstant.IS_DELETED_NO);
            addDetlEntity.setCreatorId(CurrentUserUtil.getCurrentUser().getUserId());
            addDetlEntity.setCreatorName(CurrentUserUtil.getCurrentUser().getDisplayName());
            addDetlEntity.setCreateDatetime(new Date());
            addDetlEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
            addDetlEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
            addDetlEntity.setModifyDatetime(new Date());
            addDetlEntities.add(addDetlEntity);
        }

        if(CollectionUtils.isNotEmpty(addDetlEntities)){
            flexSelfSubsidyDistrDetlDAO.insertBatch(addDetlEntities);
        }

        //封装返回数据
        ImportResDTO resDTO = new ImportResDTO();
        resDTO.setSuccessNum(addDetlEntities.size());
        resDTO.setFailNum(notPassList.size());
        if(CollectionUtils.isNotEmpty(notPassList)){
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                EasyExcel.write(out, FlexSelfSubsidyDistrInOutDTO.class).sheet("sheet1").doWrite(notPassList);
                //失败数据excel上传并返回地址
                resDTO.setFilePath(MinIoUtil.upload(out.toByteArray(), "error_data.xlsx", "qrcode", "code_on_placement"));
            }catch (Exception e){
                log.error("灵活就业或自主就业一次性补助导入后,失败文件地址获取失败,原因:{}", e.getMessage());
                e.printStackTrace();
            }
        }
        BaseResponse<ImportResDTO> baseResponse = new BaseResponse<>();
        ResponseUtils.setupSuccessResponse(baseResponse, resDTO);
        return  baseResponse;
    }

    @Override
    public BaseResponse<List<FlexSelfSubsidyDistrDetlDTO>> queryFlexSelfSubsidyDistrDetlList(FlexSelfSubsidyDistrDetlQueryRequestDTO requestDTO) throws Exception {
        final BasePagingResponse<List<FlexSelfSubsidyDistrDetlDTO>> basePagingResponse = new BasePagingResponse<>();
        serviceTemplate.execute(basePagingResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "查询一次性补助列表的入参不能为空");
                BizCheckUtil.checkNotNull(requestDTO.getPageNo(), "起始页不能为空");
                BizCheckUtil.checkNotNull(requestDTO.getPageSize(), "每页大小不能为空");
            }

            @Override
            public void executeService() {
                FlexSelfSubsidyDistrDetlEntity queryEntity = new FlexSelfSubsidyDistrDetlEntity();
                BeanUtils.copyProperties(requestDTO, queryEntity);
                PageHelper.startPage(requestDTO.getPageNo(), requestDTO.getPageSize());
                List<FlexSelfSubsidyDistrDetlEntity> flexSelfSubsidyDistrDetlEntities = flexSelfSubsidyDistrDetlDAO.queryByCondition(queryEntity);
                PageInfo<FlexSelfSubsidyDistrDetlEntity> pageInfo = new PageInfo<>(flexSelfSubsidyDistrDetlEntities);
                List<FlexSelfSubsidyDistrDetlDTO> flexSelfSubsidyDistrDetlDTOList = ToolsHelper.copyListProperties(pageInfo.getList(), FlexSelfSubsidyDistrDetlDTO::new);
                flexSelfSubsidyDistrDetlDTOList.stream().forEach(o -> {
                    o.setIdCardNum(SM4Utils.decryptDataECB(o.getIdCardNum(), "Epsoft@2024!@#$%"));
                });
                ResponseUtils.buildSuccessPagingResponse(basePagingResponse, flexSelfSubsidyDistrDetlDTOList, requestDTO,pageInfo.getTotal());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_FLEX_SELF_QUERY_LIST;
            }
        });
        return basePagingResponse;
    }

    @Override
    public BaseResponse<FlexSelfSubsidyDistrDetlDTO> queryFlexSelfSubsidyDistrDetl(FlexSelfSubsidyDistrDetlQueryRequestDTO requestDTO) throws Exception {
        final BaseResponse<FlexSelfSubsidyDistrDetlDTO> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "查询一次性补助明细的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getFlexSelfSubsidyDistrDetlId(),"一次性补助明细ID不能为空");
            }

            @Override
            public void executeService() {
                FlexSelfSubsidyDistrDetlEntity queryEntity = new FlexSelfSubsidyDistrDetlEntity();
                BeanUtils.copyProperties(requestDTO, queryEntity);
                List<FlexSelfSubsidyDistrDetlEntity> flexSelfSubsidyDistrDetlEntities = flexSelfSubsidyDistrDetlDAO.queryByCondition(queryEntity);
                if(CollectionUtils.isNotEmpty(flexSelfSubsidyDistrDetlEntities)){
                    FlexSelfSubsidyDistrDetlDTO flexSelfSubsidyDistrDetlDTO = new FlexSelfSubsidyDistrDetlDTO();
                    BeanUtils.copyProperties(flexSelfSubsidyDistrDetlEntities.get(0), flexSelfSubsidyDistrDetlDTO);
                    flexSelfSubsidyDistrDetlDTO.setIdCardNum(SM4Utils.decryptDataECB(flexSelfSubsidyDistrDetlDTO.getIdCardNum(), "Epsoft@2024!@#$%"));
                    ResponseUtils.setupSuccessResponse(baseResponse, flexSelfSubsidyDistrDetlDTO);
                }else {
                    ResponseUtils.buildSuccessResponse(new FlexSelfSubsidyDistrDetlDTO());
                }
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_FLEX_SELF_QUERY_DETL;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> updateFlexSelfSubsidyDistrDetl(FlexSelfSubsidyDistrDetlUpdRequestDTO requestDTO) throws Exception {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "修改一次性补助的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getFlexSelfSubsidyDistrDetlId(),"一次性补助明细ID不能为空");
            }

            @Override
            public void executeService() {
                //操作修改
                FlexSelfSubsidyDistrDetlEntity updateEntity = new FlexSelfSubsidyDistrDetlEntity();
                BeanUtils.copyProperties(requestDTO, updateEntity);
                updateEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                updateEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                updateEntity.setModifyDatetime(new Date());
                flexSelfSubsidyDistrDetlDAO.updateById(updateEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, updateEntity.getFlexSelfSubsidyDistrDetlId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_FLEX_SELF_UPDATE;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> delFlexSelfSubsidyDistrDetl(FlexSelfSubsidyDistrDetlUpdRequestDTO requestDTO) throws Exception {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "删除一次性补助的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getFlexSelfSubsidyDistrDetlId(),"一次性补助明细ID不能为空");
            }

            @Override
            public void executeService() {
                FlexSelfSubsidyDistrDetlEntity delEntity = new FlexSelfSubsidyDistrDetlEntity();
                delEntity.setFlexSelfSubsidyDistrDetlId(requestDTO.getFlexSelfSubsidyDistrDetlId());
                delEntity.setIsDeleted(CommonConstant.IS_DELETED_YES);
                delEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                delEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                delEntity.setModifyDatetime(new Date());
                flexSelfSubsidyDistrDetlDAO.updateById(delEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, delEntity.getFlexSelfSubsidyDistrDetlId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_FLEX_SELF_DEL;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> confirmFlexSelfSubsidyDistrDetl(FlexSelfSubsidyDistrDetlUpdRequestDTO requestDTO) throws Exception {
        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "确认一次性补助的入参不能为空");
                BizCheckUtil.checkNotBlank(requestDTO.getFlexSelfSubsidyDistrDetlId(),"一次性补助明细ID不能为空");
            }

            @Override
            public void executeService() {
                FlexSelfSubsidyDistrDetlEntity delEntity = new FlexSelfSubsidyDistrDetlEntity();
                delEntity.setFlexSelfSubsidyDistrDetlId(requestDTO.getFlexSelfSubsidyDistrDetlId());
                delEntity.setConfirmFlag(CommonConstant.CONFIRM_FLAG_YES);
                delEntity.setConfirmDatetime(new Date());
                delEntity.setModifierId(CurrentUserUtil.getCurrentUser().getUserId());
                delEntity.setModifierName(CurrentUserUtil.getCurrentUser().getDisplayName());
                delEntity.setModifyDatetime(new Date());
                flexSelfSubsidyDistrDetlDAO.updateById(delEntity);
                ResponseUtils.setupSuccessResponse(baseResponse, delEntity.getFlexSelfSubsidyDistrDetlId());
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_FLEX_SELF_UPDATE;
            }
        });
        return baseResponse;
    }

    @Override
    public void exportDistrDetlList(ExportDistrDetlRequestDTO requestDTO, HttpServletResponse response) throws Exception {
        if(ToolsHelper.isEmpty(requestDTO)){
            throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "导出入参不能为空");
        }
        String subsidyType = requestDTO.getSubsidyType();
        if(ToolsHelper.isEmpty(subsidyType)){
            throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "补助类型不能为空");
        }
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + System.currentTimeMillis() + ".xlsx");
        if(CommonConstant.SUBSIDY_TYPE_RESET.equals(subsidyType)){
            //待安置数据导出
            ResetSubsidyDistrDetlEntity queryEntity = new ResetSubsidyDistrDetlEntity();
            BeanUtils.copyProperties(requestDTO, queryEntity);
            List<ResetSubsidyDistrDetlEntity> resetSubsidyDistrDetlEntities = resetSubsidyDistrDetlDAO.queryByCondition(queryEntity);
            if(CollectionUtils.isEmpty(resetSubsidyDistrDetlEntities)){
                throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "没有查询到待安置数据明细");
            }
            List<ResetSubsidyDistrInOutDTO> resetSubsidyDistrInOutDTOList = ToolsHelper.copyListProperties(resetSubsidyDistrDetlEntities, ResetSubsidyDistrInOutDTO::new);
            resetSubsidyDistrInOutDTOList.stream().forEach(o ->{
                o.setConfirmFlag(CommonConstant.CONFIRM_FLAG_YES.equals(o.getConfirmFlag()) ? "已确认" : "未确认");
                o.setIdCardNum(SM4Utils.decryptDataECB(o.getIdCardNum(), "Epsoft@2024!@#$%"));
            });
            EasyExcel.write(response.getOutputStream(), ResetSubsidyDistrInOutDTO.class).sheet("sheet1").doWrite(resetSubsidyDistrInOutDTOList);
            return;
        } else if(CommonConstant.SUBSIDY_TYPE_FLEX.equals(subsidyType) || CommonConstant.SUBSIDY_TYPE_SELF.equals(subsidyType)){
            //灵活就业或自主就业数据导出
            FlexSelfSubsidyDistrDetlEntity queryEntity = new FlexSelfSubsidyDistrDetlEntity();
            BeanUtils.copyProperties(requestDTO, queryEntity);
            List<FlexSelfSubsidyDistrDetlEntity> flexSelfSubsidyDistrDetlEntities = flexSelfSubsidyDistrDetlDAO.queryByCondition(queryEntity);
            if(CollectionUtils.isEmpty(flexSelfSubsidyDistrDetlEntities)){
                throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "没有查询到灵活就业或一次性补助数据明细");
            }
            List<FlexSelfSubsidyDistrInOutDTO> flexSelfSubsidyDistrInOutDTOList = ToolsHelper.copyListProperties(flexSelfSubsidyDistrDetlEntities, FlexSelfSubsidyDistrInOutDTO::new);
            flexSelfSubsidyDistrInOutDTOList.stream().forEach(o ->{
                o.setConfirmFlag(CommonConstant.CONFIRM_FLAG_YES.equals(o.getConfirmFlag()) ? "已确认" : "未确认");
                o.setIdCardNum(SM4Utils.decryptDataECB(o.getIdCardNum(), "Epsoft@2024!@#$%"));
            });
            EasyExcel.write(response.getOutputStream(), FlexSelfSubsidyDistrInOutDTO.class).sheet("sheet1").doWrite(flexSelfSubsidyDistrInOutDTOList);
            return;
        }
        throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR,  "传入的补助类型不在规则范围内");
    }

    @Override
    public BaseResponse<PsnBankInfoDTO> queryPsnBankInfo(ResetSubsidyDistrDetlQueryRequestDTO requestDTO) throws Exception {
        final BasePagingResponse<PsnBankInfoDTO> baseResponse = new BasePagingResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "查询银行信息的入参不能为空");
                if(ToolsHelper.isEmpty(requestDTO.getSoldierId())){
                    throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR, "会员ID不能为空");
                }
            }

            @Override
            public void executeService() {
                PsnBankInfoBEntity queryEntity = new PsnBankInfoBEntity();
                queryEntity.setSoldierId(requestDTO.getSoldierId());
                List<PsnBankInfoBEntity> psnBankInfoBEntities = psnBankInfoBDAO.queryByCondition(queryEntity);
                if(CollectionUtils.isNotEmpty(psnBankInfoBEntities)){
                    PsnBankInfoDTO psnBankInfoDTO = new PsnBankInfoDTO();
                    BeanUtils.copyProperties(psnBankInfoBEntities.get(0), psnBankInfoDTO);
                    psnBankInfoDTO.setIdCardNum(SM4Utils.decryptDataECB(psnBankInfoDTO.getIdCardNum(), "Epsoft@2024!@#$%"));
                    ResponseUtils.setupSuccessResponse(baseResponse, psnBankInfoDTO);
                }else {
                    ResponseUtils.buildSuccessResponse(new PsnBankInfoDTO());
                }

            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_PSN_BANK_INFO_QUERY_DETL;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<ResetSubsidyDistrAppletDTO> queryResetSubsidyDistrApplet(ResetSubsidyDistrDetlQueryRequestDTO requestDTO) throws Exception {
        final BaseResponse<ResetSubsidyDistrAppletDTO> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(requestDTO, "查询待安置生活补助明细的入参不能为空");
                if(ToolsHelper.isEmpty(requestDTO.getSoldierId())){
                    throw new BizException(ErrorCodeEnum.COMMON_INNER_ERROR, "会员ID不能为空");
                }
            }

            @Override
            public void executeService() {
                ResetSubsidyDistrAppletDTO resetSubsidyDistrAppletDTO = new ResetSubsidyDistrAppletDTO();
                resetSubsidyDistrAppletDTO.setTotalMonth(0);
                resetSubsidyDistrAppletDTO.setTotalAmt(BigDecimal.ZERO);
                ResetSubsidyDistrDetlEntity queryEntity = new ResetSubsidyDistrDetlEntity();
                queryEntity.setSoldierId(requestDTO.getSoldierId());
                List<ResetSubsidyDistrDetlEntity> resetSubsidyDistrDetlEntities = resetSubsidyDistrDetlDAO.queryByCondition(queryEntity);
                if(CollectionUtils.isNotEmpty(resetSubsidyDistrDetlEntities)){
                    List<ResetSubsidyDistrDetlDTO> resetSubsidyDistrDetlDTOList = ToolsHelper.copyListProperties(resetSubsidyDistrDetlEntities, ResetSubsidyDistrDetlDTO::new);
                    resetSubsidyDistrDetlDTOList.stream().forEach(o -> {
                        o.setIdCardNum(SM4Utils.decryptDataECB(o.getIdCardNum(), "Epsoft@2024!@#$%"));
                    });
                    BigDecimal totalAmt = resetSubsidyDistrDetlDTOList.stream()
                            .map(ResetSubsidyDistrDetlDTO::getPayAmt)
                            .reduce(BigDecimal.ZERO, BigDecimal::add);
                    resetSubsidyDistrAppletDTO.setTotalMonth(resetSubsidyDistrDetlDTOList.size());
                    resetSubsidyDistrAppletDTO.setTotalAmt(totalAmt);
                    resetSubsidyDistrAppletDTO.setResetSubsidyDistrDetlDTOList(resetSubsidyDistrDetlDTOList);
                }
                ResponseUtils.setupSuccessResponse(baseResponse, resetSubsidyDistrAppletDTO);
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_PLACEMENT_RESET_QUERY_DETL;
            }
        });
        return baseResponse;
    }
}
